package com.itheima.health.util;

import com.itheima.health.dao.UserDao;
import com.itheima.health.dao.UserOperateDao;
import com.itheima.health.dto.MemberParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;
@Component
@Slf4j
public class taasktime {
    @Autowired
    UserOperateDao userOperateDao;

    @Scheduled(cron = "0 0/5 * * * ? ")
    public void procsssTimeOder(){
        log.info("定时清理");
        //没5分钟清理一场
        LocalDateTime time = LocalDateTime.now().minusMinutes(5);
       List<MemberParam> veiflcationcodeParams =  userOperateDao.getByExceedsTime(time);
       if (veiflcationcodeParams !=null || veiflcationcodeParams.size()>0){
           userOperateDao.deleteVerificationCode(time);
           log.info("本次清除了"+veiflcationcodeParams.size()+"条验证吗");
       }else {
           log.info("本次无任务清除");
       }
    }
}
